//CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!
//CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!CLIENT!!

#include <iostream>
#include <string>
#include <SDL_net.h>
#undef main

#include <assert.h>
#include "../Library/ClientSocket.h"
#include "GameMessage.h"

#define MAX_LENGTH 2000

int main(int argc, char** argv)
{
	SDL_Init(0);
	SDLNet_Init();

	std::cout<<"CLIENT\n";
	ClientSocket ClientSock;
	if(argc<3)
	{
		std::cout<<"Arguments missing \n please use format: ip port";
		return 0;
	}

	int port = atoi(argv[2]);
	const char* server = argv[1];
	std::cout<<"Connecting..\n";
	if(ClientSock.ClientOpen(server, port))
	{
		std::cout<<"Ip: "<<ClientSock.GetIp()<<"\n";
		std::cout<<"Port: "<<ClientSock.GetPort()<<"\n";
		std::cout<<"Connected\n";
	}
	else
	{
		ClientSock.Close();
	}

	while(true)
	{
		SockMessage InMsg;
		if(ClientSock.Recv(&InMsg))
		{
	
			GameMessage* gm=0;
			gm = gm->Read(&InMsg);

			if (gm)
			{
				gm->Execute();
			}
		}
	}


	system("pause");
}